import 'dart:io';

import 'package:permission_handler/permission_handler.dart';

class PermissionUtils {
  /// 认证权限
  static Future<bool> requestAuthPermission() async {
    if (Platform.isIOS) {
      return request([
        Permission.photos,
        Permission.camera,
      ]);
    } else {
      return request([
        Permission.storage,
        Permission.camera,
      ]);
    }
  }

  /// 存储权限
  static Future<bool> requestStorage() async {
    return request([Permission.storage]);
  }

  /// 图片存储
  static Future<bool> requestPhotosStorage() async {
    if (Platform.isIOS) {
      return request([Permission.photos]);
    } else {
      return request([Permission.storage]);
    }
  }

  /// 相机
  static Future<bool> requestCamera() async {
    return request([Permission.camera]);
  }

  /// 麦克风
  static Future<bool> requestMicroPhone() async {
    return request([Permission.microphone]);
  }

  /// 麦克风
  static Future<bool> requestBle() async {
    return request([Permission.bluetooth, Permission.bluetoothConnect]);
  }

  static Future<bool> request(List<Permission> permissions) async {
    final data = await permissions.request();
    return permissions
        .map((e) => data[e] == PermissionStatus.granted)
        .every((e) => e);
  }
}
